package com.kamikaze;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class RegistServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;

	public RegistServlet() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String user_id = request.getParameter("user_id");
		String user_pw = request.getParameter("user_pw");
		String user_name = request.getParameter("user_name");
		String user_gender = request.getParameter("user_gender");
		String user_birthday = request.getParameter("user_birthday");
		String user_employee = request.getParameter("user_employee");
		String user_tel = request.getParameter("user_tel");
		String user_mobile = request.getParameter("user_mobile");
		String user_address = request.getParameter("user_address");
		String user_salary = request.getParameter("user_salary");
		String dept_number = request.getParameter("dept_number");
		String user_level = request.getParameter("user_level");
		String user_image = request.getParameter("user_image");
		Member member = new Member(user_id, user_pw, user_name, user_gender,
				user_birthday, user_employee, user_tel, user_mobile,
				user_address, user_salary, dept_number, user_level, user_image);
		// 取回各欄位的值
		Member m = (Member)session.getAttribute("member");
		if(member.check()){
			response.sendRedirect("index.jsp");
		}else{
			session.setAttribute("member", member);
			response.sendRedirect("regist.jsp");
		}
	}
}